/*
* InputListener.java
* Copyright (C) 2004
* 
* $Id: InputListener.java,v 1.6 2005/06/06 18:22:20 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
using System;
namespace Suake2.UI.sys
{
	
	/// <summary> InputListener</summary>
	public sealed class InputListener : MouseWheelListener
	{
		
		// modifications of eventQueue must be thread safe!
		//UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
		private static System.Collections.ArrayList eventQueue = new System.Collections.ArrayList();
		
		internal static void  addEvent(Jake2InputEvent ev)
		{
			lock (eventQueue.SyncRoot)
			{
				eventQueue.Insert(eventQueue.Count, ev);
			}
		}
		
		internal static Jake2InputEvent nextEvent()
		{
			Jake2InputEvent ev;
			lock (eventQueue.SyncRoot)
			{
				System.Object tempObject;
				tempObject = eventQueue[0];
				eventQueue.RemoveAt(0);
				ev = (!(eventQueue.Count == 0))?(Jake2InputEvent) tempObject:null;
			}
			return ev;
		}
		
		public void  keyPressed(System.Object event_sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (!((e.getModifiersEx() & InputEvent.ALT_GRAPH_DOWN_MASK) != 0))
			{
				addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.KeyPress, e));
			}
		}
		
		public void  keyReleased(System.Object event_sender, System.Windows.Forms.KeyEventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.KeyRelease, e));
		}
		
		public void  keyTyped(System.Object event_sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if ((e.getModifiersEx() & InputEvent.ALT_GRAPH_DOWN_MASK) != 0)
			{
				addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.KeyPress, e));
				addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.KeyRelease, e));
			}
		}
		
		public void  mouseClicked(System.Object event_sender, System.EventArgs e)
		{
		}
		
		public void  mouseEntered(System.Object event_sender, System.EventArgs e)
		{
		}
		
		public void  mouseExited(System.Object event_sender, System.EventArgs e)
		{
		}
		
		public void  mousePressed(System.Object event_sender, System.Windows.Forms.MouseEventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.ButtonPress, e));
		}
		
		public void  mouseReleased(System.Object event_sender, System.Windows.Forms.MouseEventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.ButtonRelease, e));
		}
		
		public void  mouseDragged(System.Object event_sender, System.Windows.Forms.MouseEventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.MotionNotify, e));
		}
		
		public void  mouseMoved(System.Object event_sender, System.Windows.Forms.MouseEventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.MotionNotify, e));
		}
		
		public void  componentHidden(System.Object event_sender, System.EventArgs e)
		{
		}
		
		public void  componentMoved(System.Object event_sender, System.EventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.ConfigureNotify, e));
		}
		
		public void  componentResized(System.Object event_sender, System.EventArgs e)
		{
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.ConfigureNotify, e));
		}
		
		public void  componentShown(System.Object event_sender, System.EventArgs e)
		{
			JOGLKBD.c = ((System.Windows.Forms.Control) event_sender);
			addEvent(new Jake2InputEvent(event_sender, Jake2InputEvent.CreateNotify, e));
		}
		
		public void  mouseWheelMoved(MouseWheelEvent e)
		{
			addEvent(new Jake2InputEvent(Jake2InputEvent.WheelMoved, e));
		}
	}
}